package com.ruoran.user.util;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Setter
@Getter
public class Page<T> implements Serializable {

    private Integer pageSize = 10;
    private Integer pageNum = 1;
    private Long pages = 0L;
    private Long records = 0L;
    private List<T> result = new ArrayList<>();

    public Page() {
    }

    public Page(Integer pageNum, Integer pageSize) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }

    public Page(Integer pageNum, Long pages, Long records, List<T> result) {
        this.pageNum = pageNum;
        this.pages = pages;
        this.records = records;
        this.result = result;
    }

    public Page(Integer pageNum, Integer pageSize, Long pages, Long records, List<T> result) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.pages = pages;
        this.records = records;
        this.result = result;
    }

    public Long getPages() {
        if (pages == 0L) {
            return this.records % this.pageSize == 0 ? (this.records / this.pageSize) : (this.records / this.pageSize + 1);
        }
        return pages;
    }
}
